package dse.messages.singleversion;
import dse.*;
import dse.messages.*;
import dse.messages.multiversion.VersionReader;


public class MACResponseMessageHandler extends MessageSender
		implements MessageHandler {
	private VersionReader reader;
	private Integer ts;
	
	public MACResponseMessageHandler (
			Experiment experiment, 
			Integer sequence,
			VersionReader reader
			)
	{
		super(experiment);
		this.ts = sequence;
		this.reader = reader;
	}
	
	@Override
	public boolean acceptMessage(Message message) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public void messageInterupted(ExperimentRecorder recorder, Message message,
			double time) {
		// TODO Auto-generated method stub
		if(ExperimentRecorder.debug)
			recorder.debug(this, "msgIntrpt: " + message, time);
		reader.readVersion(recorder, -1, time);
	}

	@Override
	public void messageReceived(ExperimentRecorder recorder, Message message,
			double time) {
		// TODO Auto-generated method stub
		if(ExperimentRecorder.debug)
			recorder.debug(this, "msgRcvd: " + message, time);
		if (message.messageType() != MessageType.MACResponse) {
			recorder.warn(
					"ShareMACResponseMessageHandler recieved " + 
					message.messageType() + " message."
					);
			return;
		}
		
		reader.readVersion(recorder, ts, time);
	}
}
